/**
 * Created by Administrator on 2017/3/21.
 */
var page = pagesize;
var curpage = 1;
var hasMore = true;
var footer = false;
var reset = true;
var orderKey = '';
var getMid = getQueryString('mid');

$(function(){
    var key = getCookie('key');
    if(!key){
        window.location.href = WapSiteUrl+'/tmpl/member/login.html';
    }

    $('#fixed_nav').waypoint(function() {
        $('#fixed_nav').toggleClass('fixed');
    }, {
        offset: '50'
    });

    function initPage(){
        if (reset) {
            curpage = 1;
            hasMore = true;
        }
        $('.loading').remove();
        if (!hasMore) {
            return false;
        }
        hasMore = false;
        $.ajax({
            type:'post',
            url:ApiUrl+"/index.php?act=member_promotion&op=promotion_details&page="+page+"&curpage="+curpage,
            data:{key:key,mid:getMid},
            dataType:'json',
            success:function(result){
                console.log(result);
                checkLogin(result.login);//检测是否登录了
                curpage++;
                var data = result['datas']['promotion_details'];
                data.WapSiteUrl = WapSiteUrl;//页面地址
                data.ApiUrl = ApiUrl;
                data.key = getCookie('key');
                document.getElementById('total').innerHTML = data['brokerageTotal'];
                HTML = ""
                for(var i=0;i<data['orderList'].length;i++){
                     HTML+='<div class="details_item"><div class="item_l"><p class="name">'+data['orderList'][i]['orderList']['extend_order_goods'][0]['goods_name']+'</p> <p class="info"><span>数量：'+data['orderList'][i]['orderList']['extend_order_goods'][0]['goods_num']+'</span> <span>价格：'+data['orderList'][i]['orderList']['extend_order_goods'][0]['goods_price']+'￥</span></p> </div> <div class="item_r">反佣:'+data['orderList'][i]['lg_av_brokerage']+'￥ </div> </div>';
                }
                document.getElementsByClassName('content')[0].innerHTML = HTML;
            }
        });

    }




    //初始化页面
    initPage();
    $(window).scroll(function(){
        if(($(window).scrollTop() + $(window).height() > $(document).height()-1)){
            initPage();
        }
    });
});
function get_footer() {
    if (!footer) {
        footer = true;
        $.ajax({
            url: WapSiteUrl+'/js/tmpl/footer.js',
            dataType: "script"
        });
    }
}